<template>
    <div>
      <p-table 
      :columns="columns"
      bordered
      :pagination="ipagination"
      @change="handleTableChange" 
      :data-source="dataList">
      <template slot="processInstanceTitle" slot-scope="text,record">
        {{(record.level===1?'[一般]':record.level===2?'[急]':'[紧急]')+(record.processInstanceTitle||'')}}
      </template>
      <template slot="action" slot-scope="text,record">
        <a @click="handleEdit(record)">处理</a>
      </template>
      
      </p-table>
    </div>
</template>

<script>
const columns = [
  {
    title: '流程编号',
    dataIndex: 'processCode',
    key: 'processCode',
  },
  {
    title: '流程标题',
    dataIndex: 'processInstanceTitle',
    key: 'processInstanceTitle',
    scopedSlots: { customRender: 'processInstanceTitle' },
  },
  {
    title: '流程名称',
    dataIndex: 'processName',
    key: 'processName',
  },
  {
    title: '创建人',
    dataIndex: 'createName',
    key: 'createName',
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    key: 'createTime',
  },

  {
    title: '操作',
    key: 'action',
    scopedSlots: { customRender: 'action' },
  },
];

import { postAction,getAction,deleteAction } from '@/api/manage'
export default {
    data() {
        return {
           dataList:[],
           columns,
           url:{
               list:'/poros-bpmengine/task/getAssigneeTaskList/'
           },
           pager:{
             limit:10,
             pageNo:1,
           },
           ipagination: {
            current: 1,
            pageSize: 10,
            pageSizeOptions: ['10', '20', '30'],
            showTotal: (total, range) => {
              return range[0] + '-' + range[1] + ' 共' + total + '条'
            },
            total:0,
           },
        };
    },
    created() {
      console.log(this.$route.path)
    },
    mounted() {
     const query = this.$route.query
       if(query.definitionKey){
          const info = {
            definitionKey:query.definitionKey,
            ...this.pager
          }
          this.initData(info)
       }
       this.$on('reflsh',()=>{
         if(query.definitionKey){
          const info = {
            definitionKey:query.definitionKey,
            ...this.pager
          }
          this.initData(info)
       }
       })
    },
    methods: {
      handleTableChange(a,b,c){
        this.ipagination = a
        this.pager.pageNo = this.ipagination.current
        this.pager.limit = this.ipagination.pageSize
        this.initData(this.pager)
      },
        initData(params){
            getAction(this.url.list,params,'get').then(res=>{
               this.dataList = res.data.records || []
               this.dataList.map((item,index)=>{
                 const info = Object.assign({},item.processInstanceDTO)
                 this.dataList[index] = {...info,taskId:item.taskId}
                 this.ipagination.total = res.data.total || 0
               })
            })
        },
        //跳转流程
        handleEdit(record){
           window.location.href = record.callbackPath
          //  this.$router.push('/work/components/process/index?action=todo&processInstanceId=60393&taskId=60414&processDefinitionKey=mfsci')
        }
    }
};
</script>

<style scoped lang="less">
.search-pan{
    padding:10px 20px;
}
</style>
